package com.onemore.task.model;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.voovan.tools.log.Logger;

import com.alibaba.fastjson.JSONObject;
import com.onemore.task.JdbcGlobal;

public class ModelTest extends JdbcGlobal{
	final static private String test_field[] = new String[] {"SID","NAME","BYZD1","BYZD2","BYZD3",
	"BYZD4"};
	/**
     * 插入供应商
     * @param json
     * @return
     * @throws SQLException 
     */
    static public boolean insert_test(JSONObject json) throws SQLException
    {
    	String fieldStr = "";
    	String valuesStr = "";
    	List<String> listFields = new ArrayList<String>();

    	int i = 0;
    	for(i=0;i<test_field.length;i++) {
    		if(json.containsKey(test_field[i]))
    			listFields.add(test_field[i]);
    	}
    	for(i=0;i<listFields.size()-1;i++) {
    		fieldStr += listFields.get(i)+",";
    		valuesStr += "'"+json.getString(listFields.get(i))+"',";
    	}
		fieldStr += listFields.get(i);
		valuesStr += "'"+json.getString(listFields.get(i))+"'";
    	String sql = "";
    	
		//delete("ONE_TEST",test_field[0]+"='"+json.getString(test_field[0])+"'");
        //查询测试
        sql = "insert into ONE_TEST ("+fieldStr+") values("+valuesStr+")";
        Map<String, Object> map = null;
		Logger.debug(sql);
		map = getJdbcOperate().queryMap(sql);
		return true;
    }
}
